<template>
  <div>
    <Row >
      <Card>
        <div>
          <Input v-model="searchObj.name" placeholder="请输入姓名搜索..." class="searchItem"/>
          <Button type="primary" style="" class="searchButton" icon="search" @click="search()">搜索</Button>
          <Button @click="cancel">取消</Button>
        </div>
        <div class="edittable-con-1 list" style="">
          <Table border ref="selection" :columns="columns" :data="list"></Table>
        </div>
        <div style="text-align: center;margin-top: 20px">
          <Page :current="pageId" :total="totalPage" :page-size="10" @on-change='search'></Page>
        </div>
      </Card>
    </Row>
  </div>
</template>

<script>
  import { getUserTeam,getTeamApplication,delUserTeam } from '@/api/user'
  export default {
    name: 'user-customer',
    data () {
      return {
        searchObj: {
          cid: parseInt(this.$route.query.id),
          name: '',
          pageId: 1
        },
        columns: [
          {
            title: '编号',
            align: 'center',
            key: 'id',
            width: 100
          },
          {
            title: '姓名',
            align: 'center',
            key: 'name'
          },
          {
            title: '操作',
            align: 'center',
            key: 'handle',
            render: (h, params) => {
              if (this.$route.name !== 'user_team') {
                return h('div', [

                  h('Button', {
                    props: {
                      type: 'primary',
                      size: 'small'
                    },
                    style: { marginRight: '10px' },
                    on: {
                      click: () => {
                        this.goDetail(params.row.id)
                      }
                    }
                  }, '查看下级客户'),
                  h('Poptip', {
                    props: {
                      confirm: true,
                      title: '您确定要删除这条数据吗?',
                      transfer: true
                    },
                    on: {
                      'on-ok': () => {
                        this.del(params.row.id)
                      }
                    }
                  }, [
                    h('Button', {
                      props: {
                        type: 'error',
                        size: 'small'
                      }
                    }, '删除')
                  ])
                ])
              } else {
                return h('div', [
                  h('Poptip', {
                    props: {
                      confirm: true,
                      title: '您确定要删除这条数据吗?',
                      transfer: true
                    },
                    on: {
                      'on-ok': () => {
                        this.del(params.row.id)
                      }
                    }
                  }, [
                    h('Button', {
                      props: {
                        type: 'error',
                        size: 'small'
                      }
                    }, '删除')
                  ])
                ])
              }
            }
          }
        ],
        list: [],
        pageId: 1,
        totalPage: 10
      }
    },
    methods: {
      getList () {
        getUserTeam(this.searchObj).then(data => {
          this.list = data.data
          this.pageId = data.current_page
          this.totalPage = data.total
        })
      },
      goDetail (id) {
        this.$router.push({
          name: 'user_team',
          query: {
            leaderId: this.$route.query.id,
            id: id
          }
        })
      },
      search () {
        if (arguments[0]) {
          this.searchObj.pageId = arguments[0]
        }
        this.getList()
      },
      cancel () {
        this.searchObj = {
          cid: parseInt(this.$route.query.id),
            name: '',
            pageId: 1
        },
        this.getList()
      },
      del(id) {
        delUserTeam(id).then(() => {
          this.getList()
        })
      }
    },
    mounted () {
      if (this.$route.params.leaderId) {
        this.columns = [
          {
            title: '编号',
            align: 'center',
            key: 'id',
            width: 100
          },
          {
            title: '姓名',
            align: 'center',
            key: 'name'
          },
          {
            title: '贷款金额',
            align: 'center',
            key: 'name'
          }
        ]
        this.getList = () => {
          getTeamApplication(this.searchObj).then(data => {
            this.list = data.data
            this.pageId = data.current_page
            this.totalPage = data.total
          })
        }
      }
      this.getList()
    }
  }
</script>

<style scoped>

</style>
